package com.ruibang.glass.file.controller;

import com.ruibang.glass.file.service.ExportService;
import com.ruibang.glass.frequencycontrol.annotation.FrequencyControl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Api(tags = "文档导出控制器")
@RestController
@RequestMapping("/api/glass/file/export")
public class ExportController {

    @Autowired
    private ExportService exportService;

    @PostMapping("/pdf")
    @ApiOperation(value = "导出PDF文档")
    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
    @FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.IP)
    public void exportToPdf(@RequestParam String htmlContent,
                           @RequestParam String fileName,
                           HttpServletResponse response) {
        exportService.exportToPdf(htmlContent, response, fileName);
    }

    @PostMapping("/word")
    @ApiOperation(value = "导出Word文档")
    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
    @FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.IP)
    public void exportToWord(@RequestParam String htmlContent,
                            @RequestParam String fileName,
                            HttpServletResponse response) {
        exportService.exportToWord(htmlContent, response, fileName);
    }
} 